<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../../vue.js"></script>
</head>

<body>
    <div id="app">
        <h2>{{message}}</h2>
        <com-a></com-a>
    </div>
    <template id="coma">
      <div>
        <h2>{{message}}</h2>
        <button @click="fason">发送</button>
      </div>
    </template>

    <script>
        //总线模式
        // let $bus = new Vue();
        Vue.prototype.$bus = new MyEvent();
        let comA = {
            template: "#coma",
            data() {
                return {
                    message: "子组件",
                };
            },
            methods: {
                fason() {
                    console.log("fason");
                    this.$bus.$emit("myadd", this.message);
                },
            },
        };
        new Vue({
            el: "#app",
            components: {
                comA,
            },
            data: {
                message: "实例数据",
            },
            mounted() {
                this.$bus.addEvent("myadd", (res) => {
                    console.log("on");
                });
            },
        });
    </script>
</body>

</html>